<%--
  Created by IntelliJ IDEA.
  User: 陈海彬
  Date: 2023/9/25
  Time: 19:16
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>入库审核</title>
    <link rel="stylesheet" href="../../static/css/element-ui.css">
    <script src="../../static/js/vue.js"></script>
    <script src="../../static/js/axios.min.js"></script>
    <script src="../../static/js/element_index.js"></script>
</head>
<body>
<div id="app">
    <%--表格组件--%>
    <el-form :inline="true" :model="searchForm">
        <el-form-item label="分店信息">
            <el-select v-model="searchForm.branchid" placeholder="请选择要查询的分店">
                <el-option v-for="item in branchInfoList" :key="item.branchid" :label="item.branchname"
                           :value="item.branchid"></el-option>
            </el-select>
        </el-form-item>
        <el-form-item>
            <el-button type="success" @click="initInLibrayInfo(1)" icon="el-icon-search">查询</el-button>
        </el-form-item>
    </el-form>
    <%--按钮组件--%>
    <div>
        <el-button @click="refresh" type="primary" icon="el-icon-refresh">刷新</el-button>
    </div>
    <el-divider></el-divider>
    <div v-if="inLibrayList.length>0">
        <%--表格组件--%>
        <el-table
                :cell-style="{'text-align':'center'}"
                :header-cell-style="{'text-align':'center'}"
                :data="inLibrayList"
                border
                style="width: 100%">
            </el-table-column>
            <el-table-column
                    prop="id"
                    width="90px"
                    show-overflow-tooltip
                    label="入库编号">
            </el-table-column>
            <el-table-column
                    prop="date"
                    width="180px"
                    show-overflow-tooltip
                    label="入库时间">
            </el-table-column>
            <el-table-column
                    prop="status"
                    width="90px"
                    label="审核状态">
                <template slot-scope="scope">
                    <el-tag effect="dark" :type="scope.row.status==1?'warning':scope.row.status==2?'success':'danger'">
                        {{scope.row.status==1?'审核中':scope.row.status==2?'审核通过':'审核不通过'}}
                    </el-tag>
                </template>
            </el-table-column>
            <el-table-column
                    prop="staff.staffname"
                    width="80px"
                    label="操作员">
            </el-table-column>
            <el-table-column
                    prop="branch.branchname"
                    width="140px"
                    label="店名">
            </el-table-column>
            <el-table-column
                    prop="dates"
                    width="180px"
                    label="审核时间">
            </el-table-column>
            <el-table-column
                    label="详情"
                    width="120">
                <template slot-scope="scope">
                    <el-button type="info" size="medium" @click="details(scope.row.id)">详细信息</el-button>
                </template>
            </el-table-column>
            <el-table-column
                    fixed="right"
                    label="操作">
                <template slot-scope="scope">
                    <div style="display: flex;justify-content: center" v-if="scope.row.status==1">
                        <el-button @click="approved(scope.row)" type="success" size="medium">审核通过</el-button>
                        <el-button @click="rejected(scope.row.id)" type="danger" size="medium">审核驳回</el-button>
                    </div>
                </template>
            </el-table-column>
        </el-table>
        <%--分页组件--%>
        <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="page"
                :page-sizes="[5, 10, 15, 20]"
                :page-size="pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total">
        </el-pagination>
    </div>
    <el-empty v-else description="暂无数据，请添加入库数据"></el-empty>

    <%--详细信息弹出层--%>
    <el-dialog
            title="信息"
            :visible.sync="dialogVisibleInfo"
            width="90%">
        <el-table
                :data="storageInfoList"
                border
                style="width: 100%">
            <el-table-column
                    prop="id"
                    label="入库编号">
            </el-table-column>
            <el-table-column
                    prop="goodsid"
                    label="商品id">
            </el-table-column>
            <el-table-column
                    prop="goods.goodsname"
                    label="商品名称">
            </el-table-column>
            <el-table-column
                    prop="num"
                    label="入库数量">
            </el-table-column>
            <el-table-column
                    prop="goods.cprice"
                    label="进价">
            </el-table-column>
            <el-table-column
                    prop="branch.branchname"
                    label="所属分店">
            </el-table-column>
            <el-table-column
                    label="总价">
                <template slot-scope="scope">
                    <span>{{ scope.row.goods.cprice * scope.row.num }}</span>
                </template>
            </el-table-column>
        </el-table>
        <span slot="footer" class="dialog-footer">
  </span>
    </el-dialog>
    <%--审核驳回弹出层--%>
    <el-dialog
            title="提示"
            :visible.sync="rejectedVisible"
            width="30%">
        <el-input v-model="rejectedText"></el-input>
        <span slot="footer" class="dialog-footer">
    <el-button @click="rejectedVisible = false">取 消</el-button>
    <el-button type="primary" @click="rejectedConfirm">确 定</el-button>
  </span>
    </el-dialog>
</div>
<script>
    let app = new Vue({
        el: "#app",
        data: {
            page: 1,//当前页数
            pageSize: 5,//每页展示的数量
            inLibrayList: [],//入口信息
            total: 0,//总条数
            dialogVisibleInfo: false,//详细信息弹出层
            storageInfoList: [],//详细信息数据
            searchForm: {
                /*分店id*/
                branchid: undefined
            },//下拉选择框
            branchInfoList: [],//下列选择框数据
            userInfo: {},//用户基本信息
            rejectedId: undefined,//驳回id
            rejectedVisible: false,//驳回弹出层
            rejectedText: '',//驳回信息
        },
        created() {
            this.initInLibrayInfo();
            this.initBranchInfo();
            this.initUserInfo();
        },
        methods: {
            /*获取入库信息*/
            initInLibrayInfo(val) {
                if (val === 1) {
                    this.page = 1;
                }
                let self = this;
                axios.get('/inlibray/allInfo', {
                    params: {
                        page: this.page,
                        pageSize: this.pageSize,
                        branchid: this.searchForm.branchid
                    }
                }).then(res => {
                    self.inLibrayList = res.data.data.rows;
                    self.total = res.data.data.total;
                })
            },
            /*获取下拉框数据*/
            initBranchInfo() {
                let self = this;
                axios.get('/branch/list').then(res => {
                    self.branchInfoList = res.data.data;
                })
            },
            /*获取用户基本信息*/
            initUserInfo() {
                axios.post('/login/info').then(res => {
                    this.userInfo = res.data.data
                })
            },
            /*切换每页最大展示数量*/
            handleSizeChange(val) {
                this.pageSize = val;
                this.initInLibrayInfo();
            },
            /*切换页面*/
            handleCurrentChange(val) {
                this.page = val;
                this.initInLibrayInfo();
            },
            /*获取详细信息*/
            details(id) {
                this.dialogVisibleInfo = true;
                axios.get('/storageVolume/list', {
                    params: {
                        id: id
                    }
                }).then(res => {
                    this.storageInfoList = res.data.data[0].list;
                })
            },
            /*审核通过*/
            approved(row) {
                /*判断是否有权利审核通过*/
                if (row.branchid !== this.userInfo.branchid) {
                    this.$message('对不起，你没有权限审核该入库审核');
                } else {
                    this.$confirm('确定通过该审核吗?', '信息', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消'
                    }).then(() => {
                        axios.post('/branchGoods/updateShoing?id=' + row.id).then(res => {
                            console.log(res)
                            if (res.data.code === 200) {
                                this.initInLibrayInfo();
                                this.$message({
                                    type: 'success',
                                    message: '操作成功!'
                                });
                            }
                        })
                    }).catch(() => {
                        this.$message({
                            type: 'info',
                            message: '已取消审核'
                        });
                    });

                }
            },
            /*审核驳回按钮*/
            rejected(id) {
                this.rejectedVisible = true;
                this.rejectedId = id;
            },
            /*驳回确定按钮*/
            rejectedConfirm() {
                console.log(this.rejectedText)
                axios.post('/inlibray/reviewRejected?id=' + this.rejectedId + '&rejectedText=' + this.rejectedText).then(res => {
                    if (res.data.code === 200) {
                        this.$message({
                            message: '操作成功',
                            type: 'success'
                        });
                    } else {
                        this.$message.error('操作失败，请联系管理员！');
                    }
                    this.initInLibrayInfo();
                })
                this.rejectedVisible = false;
            },
            /*进行页面刷新*/
            refresh() {
                this.page = 1;
                this.pageSize = 5;
                this.initInLibrayInfo();
            }
        }
    })
</script>
</body>
</html>
